/*
 * @Author: yangfan 1437446666@qq.com
 * @Date: 2023-02-27 21:42:25
 * @LastEditors: yangfan 1437446666@qq.com
 * @LastEditTime: 2023-02-28 21:34:37
 * @FilePath: \s_2006A_shixun\src\utils\filterRouter.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
//过滤出允许访问的路由表

/***@name 路由变的渲染 */
export const filterRouter = (routerList, author) => {
  //如果是管理员 全部返回
  if (author === '管理员') {
    return routerList
  } else {
    //否则进行筛选
    const res = routerList.filter((item) => {
      return item.meta.auth.includes(author)
    })
    //循环
    res.length &&
      res.forEach((item) => {
        //判断是否有子路由
        if (item.children) {
          //进行递归
          item.children = filterRouter(item.children, author)
        }
      })
    return res
  }
}
